<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/1 0001
 * Time: 上午 10:34
 */

namespace app\admin\model;


use think\Model;
use think\Db;

class Evaluate extends Model
{
    protected  $pk='evaluate_id';//主键
    protected $table = 'xcx_order_evaluate';
    public function getAllEvaluate()
    {
        $res=$this->order('evaluate_id desc')->select();
        foreach ($res as $k=>$v)
        {
            $v['img_url']=[];
            $img_id=explode(',',$v['evaluate_img']);
            $v['img_url']=db('evaluate_img')->whereIn('eimg_id',$img_id)->field('eimg_url')->select();
            $v['pro_name']=db('products')->where('products_id',$v['product_id'])->field('products_name')->find();
            $v['order_number']=db('order')->where('order_id',$v['order_id'])->value('order_number');
            $res[$k]=$v;
        }
        return $res;
    }
    public function shelf($data)
    {
        $pspeci_states=$this->where('evaluate_id',$data['id'])->value('state');

        if($pspeci_states==1)
        {
            $result=$this->where('evaluate_id',$data['id'])->update(['state'=>0]);
        }else
        {
            $result=$this->where('evaluate_id',$data['id'])->update(['state'=>1]);
        }
        if(false === $result){
            // 验证失败 输出错误信息
            return ['valid'=>1,'msg'=>'操作失败'];
        }else{
            return ['valid'=>4,'msg'=>'操作成功'];
        }
    }
}